home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / DLL Source Code / SampMem.c < prev   
Encoding:
C/C++ Source or Header  |  1989-08-27  |  1.6 KB  |  66 lines  |  [TEXT/MPS ]

  1. /************************************************/
  2. /*                  Sample DLL's                */
  3. /*       Copyright © Vincent Parsons 1989.      */
  4. /************************************************/
  5. /*    DLL code for MPW C 3.0 or THINK C 4.0     */
  6. /*       with Excel for the Macintosh 2.2       */
  7. /*             and Microsoft C 5.1              */
  8. /*          with Excel for Windows 2.1          */
  9. /************************************************/
  10. /* SampMem is an example of using memory        */
  11. /* management to save a value from one          */
  12. /* execution of a DLL to the next               */
  13. /************************************************/
  14. /*   =REGISTER("SampDLLs","SampMem","JIJ")      */
  15. /*   Macintosh only.                            */
  16. /************************************************/
  17.  
  18. #include "DLL.h"
  19.  
  20. typedef long * LongPtr;
  21.  
  22. #if applec
  23. #include <Types.h>
  24. #include <Memory.h>
  25.  
  26. #endif
  27.  
  28. #if THINK_C
  29. pascal unsigned long main(short opcode, unsigned long u1);    /* prototype */
  30.  
  31. pascal unsigned long main(opcode, u1)
  32. short opcode;
  33. unsigned long u1;
  34.  
  35. #elif applec
  36. pascal unsigned long SampMem(short opcode, unsigned long u1)
  37.  
  38. #endif
  39. {
  40.     unsigned long tempLong;
  41.     unsigned long result;
  42.  
  43.     switch (opcode) {
  44.     case 0:    
  45.                 result = (unsigned long)NewHandle(4);
  46.                 *((LongPtr)(*((Handle)result))) = u1;
  47.                 break;
  48.     case 1:    
  49.                 tempLong = *((LongPtr)(*((Handle)u1)));
  50.                 tempLong++;
  51.                 *((LongPtr)(*((Handle)u1))) = tempLong;
  52.                 result = tempLong;
  53.                 break;
  54.     case 2:    
  55.                 DisposHandle((Handle)u1);
  56.                 result = 0;
  57.                 break;
  58.     default:    
  59.                 result = 0;
  60.                 break;
  61.     }
  62.     return ( result );
  63. }
  64.  
  65. /************************************************/
  66.